import { numMulti, accDiv, numSub } from '@/util'
const checkRate = (rate) => {
  let result = true
  const tarRate = parseFloat(rate)
  if (isNaN(tarRate) || tarRate * 1 === 0) {
    result = false
  }
  return result
}
const compareNum = (tarItem) => {
  let result = false
  const rate = parseFloat(tarItem.taxRate) / 100
  console.log(numMulti(tarItem.excludingTaxAmount, rate), '拉拉', tarItem.taxAmount)
  if (Math.abs(numSub(numMulti(tarItem.excludingTaxAmount, rate), tarItem.taxAmount)) <= 0.01) {
    result = true
  }
  return result
}
export const checkRowTax = function (item) {
  let result = false
  if (item.invoiceDetailDTOS) {
    item.invoiceDetailDTOS.forEach(tarItem => {
      const tarRate = accDiv(tarItem.taxAmount, tarItem.excludingTaxAmount).toFixed(3)
      console.log(tarRate, 'tarRatetarRate')
      if (checkRate(tarItem.taxRate) && !compareNum(tarItem)) {
        result = true
      }
    })
  }
  return result
}
export const checkSingleRow = function (tarItem) {
  let result = false
  const tarRate = accDiv(tarItem.taxAmount, tarItem.excludingTaxAmount).toFixed(3)
  console.log(tarRate, 'tarRatetarRate')
  if (checkRate(tarItem.taxRate) && !compareNum(tarItem)) {
    result = true
  }
  return result
}